package com.lzhsite.technology.designPattern.mediator.DepartmentDemo;

import java.util.ArrayList;
import java.util.Collection;

public class DepartmentUserMediatorImplement
{
    private static DepartmentUserMediatorImplement mediator = new DepartmentUserMediatorImplement();
    private final Collection<DepartmentUserModel> departmentUserModels = new ArrayList<DepartmentUserModel>();

    private DepartmentUserMediatorImplement()
    {
        initTestData();
    }

    public static DepartmentUserMediatorImplement getInstance()
    {
        return mediator;
    }

    private void initTestData()
    {
        DepartmentUserModel departmentUserModel1 = new DepartmentUserModel();
        departmentUserModel1.setUserId("DepartmentUser1");
        departmentUserModel1.setDepartmentId("Department1");
        departmentUserModel1.setUserId("User1");
        departmentUserModels.add(departmentUserModel1);

        DepartmentUserModel departmentUserModel2 = new DepartmentUserModel();
        departmentUserModel2.setUserId("DepartmentUser2");
        departmentUserModel2.setDepartmentId("Department1");
        departmentUserModel2.setUserId("User2");
        departmentUserModels.add(departmentUserModel2);

        DepartmentUserModel departmentUserModel3 = new DepartmentUserModel();
        departmentUserModel3.setUserId("DepartmentUser3");
        departmentUserModel3.setDepartmentId("Department2");
        departmentUserModel3.setUserId("User3");
        departmentUserModels.add(departmentUserModel3);

        DepartmentUserModel departmentUserModel4 = new DepartmentUserModel();
        departmentUserModel4.setUserId("DepartmentUser4");
        departmentUserModel4.setDepartmentId("Department2");
        departmentUserModel4.setUserId("User4");
        departmentUserModels.add(departmentUserModel4);

        DepartmentUserModel departmentUserModel5 = new DepartmentUserModel();
        departmentUserModel5.setUserId("DepartmentUser5");
        departmentUserModel5.setDepartmentId("Department2");
        departmentUserModel5.setUserId("User5");
        departmentUserModels.add(departmentUserModel5);
    }

    public boolean deleteDepartment(String departmentId)
    {
        Collection<DepartmentUserModel> tempCollection = new ArrayList<DepartmentUserModel>();
        for (DepartmentUserModel departmentUserModel : departmentUserModels)
        {
            if (departmentUserModel.getDepartmentId().equals(departmentId))
            {
                tempCollection.add(departmentUserModel);
            }
        }
        departmentUserModels.removeAll(tempCollection);
        return true;
    }

    public boolean deleteUser(String userId)
    {
        Collection<DepartmentUserModel> tempCollection = new ArrayList<DepartmentUserModel>();
        for (DepartmentUserModel departmentUserModel : departmentUserModels)
        {
            if (departmentUserModel.getUserId().equals(userId))
            {
                tempCollection.add(departmentUserModel);
            }
        }
        departmentUserModels.removeAll(tempCollection);
        return true;
    }

    public void ShowDepartmentUsers(Department department)
    {
        for (DepartmentUserModel departmentUserModel : departmentUserModels)
        {
            if (departmentUserModel.getDepartmentId().equals(department.getDepartmentId()))
            {
                System.out.println("部门编号：" + department.getDepartmentId() + " 下面拥有人员，其编号是：" + departmentUserModel.getUserId());
            }
        }
    }

    public void showUsersDepartment(User user)
    {
        for (DepartmentUserModel departmentUserModel : departmentUserModels)
        {
            if (departmentUserModel.getUserId().equals(user.getUserId()))
            {
                System.out.println("人员编号：" + user.getUserId() + " 所属部门编号是：" + departmentUserModel.getDepartmentId());
            }
        }
    }

    public boolean changeDepartment(String userId, String oldDepartmentId, String newDepartmentId)
    {
        return false;
    }

    public boolean joinDepartment(Collection<String> departmentIds, Department newDepartment)
    {
        return false;
    }
}
